package com.example.myinitializrspringbootapp.config;


import com.example.myinitializrspringbootapp.WebFilter.RequestTest1Filter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.servlet.Filter;

@Configuration
public class WebFilterConfig {
    @Bean
    public FilterRegistrationBean filterRegistrationBean(){
        FilterRegistrationBean<Filter> frBean=new FilterRegistrationBean<>();
        RequestTest1Filter requestTest1Filter=new RequestTest1Filter();
        frBean.setFilter(requestTest1Filter);        //将自定义的过滤器配置到生产过滤器的工厂中
        frBean.addUrlPatterns("/html/*");   //路径
        frBean.addInitParameter("name","filter-test1");   //设置过滤器的初始化参数
        frBean.setName("requestTest1Filter");        //过滤器名字
        frBean.setOrder(4);            //过滤器优先级,值越小越先执行
        return frBean;
    }
}
